﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;


using LRSTaxServices.Biz;
using LRSTaxServices.Common;

public partial class Controls_UserTaxDocumentsList : System.Web.UI.UserControl
{
    #region Types

    public class EditRequestedEventArgs : EventArgs
    {
        #region Construction / Disposal

        public EditRequestedEventArgs() { }

        public EditRequestedEventArgs(UserTaxDocuments usertaxdocuments)
        {
            UTD = usertaxdocuments;
        }

        #endregion

        #region Public Properties

        public UserTaxDocuments UTD
        {
            get { return (_utd); }
            set { _utd = value; }
        } private UserTaxDocuments _utd = null;

        #endregion
    }

    public delegate void EditRequestedEventHandler(object sender, EditRequestedEventArgs evt);

    #endregion

    #region Constants

    private const string PROP_ENABLE_ADDNEW = "__UserTaxDocumentsListControl::EAN";

    #endregion

    #region Public Properties

    /// <summary>
    /// Gets / sets the object used as the data source for this control.
    /// </summary>
    public UserTaxDocumentsCollection DataSource
    {
        get
        {
            if (_dataSource == null)
            {
                if (DataSourceRequested != null)
                    DataSourceRequested(this, EventArgs.Empty);
            }
            return (_dataSource);
        }
        set
        {
            if (_dataSource != value)
            {
                _dataSource = value;
            }
        }
    } private UserTaxDocumentsCollection _dataSource = null;


    public bool EnableAddNew
    {
        get { return (ViewState[ClientID + PROP_ENABLE_ADDNEW] is bool ? (bool)ViewState[ClientID + PROP_ENABLE_ADDNEW] : true); }
        set { ViewState[ClientID + PROP_ENABLE_ADDNEW] = value; }
    }

    #endregion

    #region Public Events

    public event EditRequestedEventHandler EditRequested;

    public event EventHandler AddNewRequested;

    public event EventHandler DataSourceRequested;

    #endregion

    #region Public Methods

    /// <summary>
    /// Method initializes and binds the controls UI elements.
    /// </summary>
    public bool DataBind(UserTaxDocumentsCollection usertaxdocumentsc)
    {
        DataSource = usertaxdocumentsc;
        GridUserTaxDocumentsList.DataSource = DataSource;
        GridUserTaxDocumentsList.DataBind();

        return (true);
    }

    #endregion

    #region Event Handlers

    #region Page Load

    protected void Page_Load(object sender, EventArgs e)
    {

    }

    #endregion

    #region Grid Events

    protected void GridUserTaxDocumentsList_EditCommand1(object source, DataGridCommandEventArgs evt)
    {
        DataGridItem item = evt.Item as DataGridItem;
        UserTaxDocuments usertaxdocuments = DataSource[item.DataSetIndex];

        //if (GridUserTaxDocumentsList.EditItems.Count > 0)
        //    GridUserTaxDocumentsList.MasterTableView.ClearEditItems();

        if (EditRequested != null)
            EditRequested(this, new EditRequestedEventArgs(usertaxdocuments));
    }
    protected void GridUserTaxDocumentsList_ItemCommand1(object source, DataGridCommandEventArgs evt)
    {
        if (evt.CommandName.ToUpper() == "INSERT")
        {
            if (AddNewRequested != null)
                AddNewRequested(this, EventArgs.Empty);
        }
        else if (evt.CommandName.ToUpper() == "DELETE")
        {
        }
    }

    #endregion

    #endregion

}
